// bzoj1131
// 题意：给定n(<=10^6)个节点的数，问选定一个节点，使得所有节点到这个节点的
//       距离和最大。如果有多个点输出编号最小的那个。
//
// 题解：简单的dp。两次dfs就能维护出来。
//
// run: $exec < input
#include <iostream>

int const maxn = 1000007;
int head[maxn], end_point[maxn * 2], next[maxn * 2];
int alloc = 2;
int n, ans;
long long max;

int sub_size[maxn];

void add_edge(int u, int v)
{
	end_point[alloc] = v; next[alloc] = head[u]; head[u] = alloc++;
	end_point[alloc] = u; next[alloc] = head[v]; head[v] = alloc++;
}

long long dfs(int u, int parent, int dep)
{
	long long ret = dep;
	sub_size[u] = 1;
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		if (v == parent) continue;
		ret += dfs(v, u, dep + 1);
		sub_size[u] += sub_size[v];
	}
	return ret;
}

void dfs2(int u, int parent, long long sum)
{
	if (sum > max) { max = sum; ans = u; }
	else if (sum == max && u < ans) ans = u;
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		if (v == parent) continue;
		int other = n - sub_size[v];
		long long tmp = sum + other - sub_size[v];
		dfs2(v, u, tmp);
	}
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n;
	for (int i = 1, x, y; i < n; i++) {
		std::cin >> x >> y;
		add_edge(x, y);
	}
	long long sum = dfs(1, -1, 0);
	dfs2(1, -1, sum);
	std::cout << ans << '\n';
}

